package com.tony.mindweather;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableAsync //开启异步注解功能
@EnableScheduling // 开启定时
public class MindWeatherApplication implements CommandLineRunner {

    @Autowired
    private ApplicationContext appCtx;

    @Autowired
    private StringEncryptor tonyEncryptorBean;

    public static void main(String[] args) {
        SpringApplication.run(MindWeatherApplication.class, args);

    }

    @Override
    public void run(String... args) throws Exception {
        /*Environment environment = appCtx.getBean(Environment.class);
        // 首先获取配置文件里的原始明文信息
        String qqMailUsername = environment.getProperty("spring.mail.username");
        String qqMailPassword = environment.getProperty("spring.mail.password");
        String sayloveurlAPIKEY = environment.getProperty("sayloveurlAPIKEY");
        final String weChatMessageToken = environment.getProperty("weChatMessageToken");
        final String TonyWeChatID = environment.getProperty("TonyWeChatID");

        // 加密
        String qqMailEncryptUsername = encrypt( qqMailUsername );
        String qqMailEncryptPassword = encrypt( qqMailPassword );
        String sayloveEncryptAPIKEY = encrypt( sayloveurlAPIKEY );
        final String weChatMessageEncryptToken = encrypt(weChatMessageToken);
        final String TonyEncryptWeChatID = encrypt(TonyWeChatID);

        System.out.println("qqMailEncryptUsername:" + qqMailEncryptUsername);
        System.out.println("qqMailEncryptPassword:" + qqMailEncryptPassword);
        System.out.println("sayloveEncryptAPIKEY:" + sayloveEncryptAPIKEY);
        System.out.println("weChatMessageEncryptToken:" + weChatMessageEncryptToken);
        System.out.println("TonyEncryptWeChatID:" + TonyEncryptWeChatID);*/


    }

    private String encrypt( String originPassord ) {
        String encryptStr = tonyEncryptorBean.encrypt( originPassord );
        return encryptStr;
    }

    private String decrypt( String encryptedPassword ) {
        String decryptStr = tonyEncryptorBean.decrypt( encryptedPassword );
        return decryptStr;
    }
}
